package com.ruoyi;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class GitInitializer {
    public static void main(String[] args) throws IOException {
        String repositoryPath = System.getProperty("user.dir") + "/firmwares";
        Path path = Paths.get(repositoryPath);
        if (!Files.exists(path)) {
            Files.createDirectories(path);
        }
        // 检查本地库是否已存在
        File gitDir = new File(repositoryPath + "/.git");
        boolean isRepositoryExists = gitDir.exists();

        if (!isRepositoryExists) {
            try {
                Git git = Git.init().setDirectory(new File(repositoryPath)).call();
                System.out.println("Initialized empty Git repository");
            } catch (GitAPIException e) {
                e.printStackTrace();
            }
        }
    }
}
